home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.4 KB | 244 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFcsSet.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWFCSSET_H
- #include "FWFcsSet.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODFocusSet_xh
- #include <FocusSet.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwodutil
- #endif
-
- //========================================================================================
- // class FW_CFocusSet
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::FW_CFocusSet
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSet::FW_CFocusSet(Environment* ev, ODSession* session) :
- fFocusSetRep(NULL),
- fSession(session)
- {
- fFocusSetRep = new FW_CFocusSetRep(ev, session);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::FW_CFocusSet
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSet::FW_CFocusSet(const FW_CFocusSet& other) :
- fFocusSetRep(NULL),
- fSession(other.fSession)
- {
- other.fFocusSetRep->Acquire();
- fFocusSetRep = other.fFocusSetRep;
- fFociCount = other.fFociCount;
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::~FW_CFocusSet
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSet::~FW_CFocusSet()
- {
- FW_START_DESTRUCTOR
-
- fFocusSetRep->Release();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::operator =
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSet& FW_CFocusSet::operator=(const FW_CFocusSet& other)
- {
- if (fFocusSetRep != other.fFocusSetRep)
- {
- fFocusSetRep->Release();
-
- other.fFocusSetRep->Acquire();
- fFocusSetRep = other.fFocusSetRep;
- fFociCount = other.fFociCount;
- FW_ASSERT(fSession == other.fSession);
- }
-
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::CopyIfShared
- //----------------------------------------------------------------------------------------
-
- void FW_CFocusSet::CopyIfShared(Environment* ev)
- {
- if (fFocusSetRep->GetRefCount() > 1)
- {
- FW_CFocusSetRep* newFocusSetRep = new FW_CFocusSetRep(ev, fSession);
-
- FW_CFocusSetIterator ite(ev, *this);
- for (ODTypeToken token = ite.First(ev); ite.IsNotComplete(ev); ite.Next(ev))
- {
- newFocusSetRep->fODFocusSet->Add(ev, token);
- }
-
- fFocusSetRep->Release();
- fFocusSetRep = newFocusSetRep;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::Add
- //----------------------------------------------------------------------------------------
-
- void FW_CFocusSet::Add(Environment* ev, ODTypeToken focus)
- {
- if (!fFocusSetRep->fODFocusSet->Contains(ev, focus))
- {
- CopyIfShared(ev);
-
- fFociCount++;
- fFocusSetRep->fODFocusSet->Add(ev, focus);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::Remove
- //----------------------------------------------------------------------------------------
-
- void FW_CFocusSet::Remove(Environment* ev, ODTypeToken focus)
- {
- if (fFocusSetRep->fODFocusSet->Contains(ev, focus))
- {
- CopyIfShared(ev);
-
- fFociCount--;
- fFocusSetRep->fODFocusSet->Remove(ev, focus);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::Contains
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CFocusSet::Contains(Environment* ev, ODTypeToken focus) const
- {
- return fFocusSetRep->fODFocusSet->Contains(ev, focus);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::RelinquishFocusSet
- //----------------------------------------------------------------------------------------
-
- void FW_CFocusSet::RelinquishFocusSet(Environment* ev, ODFrame* frame) const
- {
- fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, fFocusSetRep->fODFocusSet, frame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::RequestFocusSet
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CFocusSet::RequestFocusSet(Environment* ev, ODFrame* frame) const
- {
- if (fFociCount != 0)
- return fSession->GetArbitrator(ev)->RequestFocusSet(ev, fFocusSetRep->fODFocusSet, frame);
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSet::CreateFocusSetIterator
- //----------------------------------------------------------------------------------------
-
- ODFocusSetIterator* FW_CFocusSet::CreateFocusSetIterator(Environment* ev) const
- {
- return fFocusSetRep->fODFocusSet->CreateIterator(ev);
- }
-
- //========================================================================================
- // class FW_CFocusSetRep
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSetRep::FW_CFocusSetRep
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSetRep::FW_CFocusSetRep(Environment* ev, ODSession* session) :
- fODFocusSet(NULL)
- {
- fODFocusSet = session->GetArbitrator(ev)->CreateFocusSet(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSetRep::~FW_CFocusSetRep
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSetRep::~FW_CFocusSetRep()
- {
- delete fODFocusSet;
- fODFocusSet = NULL;
- }
-
- //========================================================================================
- // class FW_CFocusSetIterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSetIterator::FW_CFocusSetIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSetIterator::FW_CFocusSetIterator(Environment* ev, const FW_CFocusSet& focusSet)
- {
- fIterator = focusSet.CreateFocusSetIterator(ev);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFocusSetIterator::~FW_CFocusSetIterator
- //----------------------------------------------------------------------------------------
-
- FW_CFocusSetIterator::~FW_CFocusSetIterator()
- {
- FW_START_DESTRUCTOR
-
- delete fIterator;
- fIterator = NULL;
- }
-